import axios from "axios";
const request = axios.create({
  baseURL: import.meta.env.VITE_API_URL,
  timeout: 60000,
});

request.interceptors.request.use(
  function (config) {
    var token = window.localStorage.getItem("token");
    if (!token) {
      token = window.localStorage.getItem("api_token");
    }
    if(process.env.NODE_ENV !== "production"){
      // token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiOTlmYTU0YjEzNGM1ZDA2YzBkMzcwNTcxOGNhMDA5NTc5ZWJhZTY0NWQ3Y2E0ZjBlZDA5NTU4NTJjZGRkYTZjZDA0YmQyMDkzYTQxMmJmZjQiLCJpYXQiOjE3MDQ5NTQ3NzIsIm5iZiI6MTcwNDk1NDc3MiwiZXhwIjoxNzM2NTc3MTcyLCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.Cyj1Az0IpEWs2X1XxJ7_6mCua_rMV6Wrv-CDMHmGg37fQvYvNXjULYvJTsfE6L-IAZQV3ZY35ovZY5_YbIaQrlg6h0D0PCG9VqAQj2f5Her3c5Y4n17aUTG89p39cTRJ5J9HCGAebPmcdY-kbbzirWx_H-sa1Pdd06j0KzTByBv8bz3cjLjFpEI7Aa22r4kK_XhCfgCkMWKuWBAgICnN58rBDXgY-QfoNUI5tLckim8_oSQALywiLMs3xWBOvOxUPe8JD--DOBrny9f2vicf_GSBgDTsk3C8ti4sKb_Msngn129WGZA2hqA77jG0gbuxm2ZFok258qMytxvawGze50_CLuaG9mdDLrCHPaIgYBQX4kpPVFXVbIGvZ-XKtsWiN8_3NqG5y4NgR_a9aoLt2VIbQdD4f7TxZYYYpGv0c1scYTMcxmn31QfjNqLy8qY_y4EbHGaToJ69xu9wmDLci-bdiA5xywFSf1sKpjQFRFd5X1yIhHyEEtCqAIjnXKhVbf8EYGMJJAs1vvGlgxVHhwbFHXdGhKgPSqREEinSasq7wQp6LupMsQq3MhmnLU99pQjKu34loAUdEJ7N1GKNkIPDceW8TsMVFTQ-pAqacfrvjwQfOtBCjpo_RHQCanWaLgOBbGWZMEEkpY6le9ZuSFrd-02nLNOz2bWu-PZTVk4";
    }
    let url = config.url;
    config.url = url;
    if(token){
      config.headers["Authorization"] = "Bearer " + token;
    }
    return config;
  },
  function (error) {
    // Do something with request error
    return Promise.reject(error);
  },
);

request.interceptors.response.use(
  function (response) {
    return response.data;
  },
  function (error) {
    return Promise.reject(error);
  },
);
export { request as http };
